<template>
  <div :class="['show-hall-desc', $ua.isFromPc() ? 'z-web' : 'z-phone']">
    <div class="work-list" v-if="work_list.length > 0">
      <div class="content" v-for="(item, i) in work_list" :key="i">
        <div class="video-content" v-if="item.type == 1">
          <client-only>
            <video-player
              :ref="'videoPlayer' + item.data_id"
              :options="PlayerArry[i]"
              @ended="onPlayerEnded($event)"
              @play="onPlayerPlay($event, item.data_id)"
              :playsinline="true"
              class="video-player vjs-custom-skin" >
            </video-player>
          </client-only>
          <div class="name" :title="item.name">
            {{ item.name }}
          </div>
          <div class="art_name">
            {{ item.art_name }}
            <div class="collect">
              <img src="@/static/img/editPersonalHome/zhenyan.png" alt="">
              {{ item.view_times }}
            </div>
          </div>
        </div>
        <div v-else class="work-content" @click="lookBig(item.opus_id[0]?.id)">
          <img :src="getBigImg(item.opus_id[0]?.id)" alt="">
          <div class="name" :title="item.name">
            {{ item.name }}
          </div>
          <div class="art_name">
            {{ item.art_name }}
            <div class="collect">
              <img src="@/static/img/editPersonalHome/zhenyan.png" alt="">
              {{ item.view_times }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <Pagin
      ref="page"
      v-show="work_list.length !== 0"
      :func="getBoutiqueWork"
      :pagesSizes="[10, 20, 30, 50]"
      :sizeNum="8"
      :layout="'prev, pager, next'"
      :background="true"
      :position="'center'"
      class="pagin"
    ></Pagin>
  </div>
</template>

<script>
import { getToken } from '../../utils/auth'
import { getBigImg } from '../../utils/downloadFile'
import Pagin from "@/components/pagin.vue";
export default {
  scrollToTop: true,
  name: 'showHallDesc',
  components: {
    Pagin
  },
  data() {
    return {
      boutiqueData: {},
      artData: {},
      active_id: '',
      active: 0,
      work_list: [],
      VideoIndex: 0,
      VideoArry: [],
      PlayerArry: [],
      currentPlayer: null,
      playerOptions: {//video-player组件播放视频所需的参数，此参数作为模板用于复制
        controls: true, // 是否显示控制栏
        // playbackRates: [ 0.5, 1.0, 1.5, 2.0 ], //可选择的播放速度
        autoplay: false, //如果true,浏览器准备好时开始回放。
        muted: true, // 默认情况下将会消除任何音频。
        loop: false, // 视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [
          // { type : "",src : 'http://www.html5videoplayer.net/videos/madagascar3.mp4'} //url地址
        ],
        poster: "", //你的封面地址
        // width: document.documentElement.clientWidth,//视频画面宽度
        notSupportedMessage: '此视频暂无法播放，请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: false,//当前时间和持续时间的分隔符
          durationDisplay: false,//显示持续时间
          remainingTimeDisplay: false,//是否显示剩余时间功能
          fullscreenToggle: true,  //全屏按钮
          progressControl: false,
          volumePanel: true
        },
        playtimes: 0,//视频播放起点
        preload: "auto"
      },
    }
  },
  mounted() {
    this.refresh()
  },
  methods: {
    getBigImg,
    refresh() {
      // this.$nextTick(() => {
        this.$refs.page.refresh()
        console.log(this.$refs)
      // })
    },
    getBoutiqueWork(page, page_size, callback) {
      const params = {
        stadiums_id: this.$route.query.data_id,
        page_num: page,
        page_count: page_size
      }
      if (this.$route.query.type == 'boutique') {
        this.$api.getBoutiqueWork(params).then(res => {
          this.work_list = Array.isArray(res.result.item_list) ? res.result.item_list : []
          this.work_list.forEach((v, i) => {
            if (v.type == 1) {
              let op = JSON.parse(JSON.stringify(this.playerOptions));
              op.sources = [{ type : "video/mp4" ,src: v.video_url }];
              op.poster = v.title_page || ''
              this.PlayerArry.push(op);
            } else {
              this.PlayerArry.push({})
            }
          })
          callback(this.work_list, res.result.total_count)
        })
      } else {
        this.$api.getArtWork(params).then(res => {
          this.work_list = Array.isArray(res.result.item_list) ? res.result.item_list : []
          this.work_list.forEach((v, i) => {
            if (v.type == 1) {
              let op = JSON.parse(JSON.stringify(this.playerOptions));
              op.sources = [{ type : "video/mp4" ,src: v.video_url }];
              op.poster = v.title_page || ''
              this.PlayerArry.push(op);
            } else {
              this.PlayerArry.push({})
            }
          })
          callback(this.work_list, res.result.total_count)
        })
      }
    },
    // 查看大图
    lookBig(id) {
      console.log(id)
      if (!getToken()) return this.$message.warning('请您先登陆才可以查看大图')
      if (process.browser && id) {
        let {
          BasicDraw,
          BigImageShow
        } = require("../../utils/main.js")
        let basicDraw = new BasicDraw(); // 创建基础渲染类
        basicDraw.start(); // 开始渲染
        new BigImageShow().showBigImg(id)

        document.getElementById('bigIamgeClose').addEventListener('click', (e) => {
          basicDraw.dispose()
          e.stopPropagation()
        })
      }
    },
  }
}
</script>

<style lang="less" scoped>
.show-hall-desc {
  &.z-web {
    padding: 80px 276px 80px;
    background-color: #fff;

    .work-list {
      background-color: #fff;
      padding: 0 0 50px;
      display: grid;
      justify-content: space-between;
      grid-template-columns: repeat(auto-fill, 320px);
      grid-gap: 10px;

      .content {
        // width: 320px;
        // height: 240px;
        margin-bottom: 30px;

        .work-content {
          height: 100%;
          width: 100%;

          img {
            width: 320px;
            height: 240px;
            object-fit: cover;
          }
        }

        .work-content,
        .video-content {
          font-size: 16px;
          color: #999;
          font-weight: bold;
          cursor: pointer;

          .el-image {
            width: 100%;
            height: 100%;
          }

          .name {
            width: 320px;
            color: #000;
            font-weight: 600;
            margin: 6px 0;
            overflow: hidden; //超出的文本隐藏
            text-overflow: ellipsis; //溢出用省略号显示
            white-space: nowrap;
          }
          .art_name,
          .desc {
            color: #999;
            margin-bottom: 10px;
          }
          .collect {
            float: right;
            img {
              // width: 30px;
              width: 18px;
              height: 18px;
              position: relative;
              top: -3px;
              margin-right: 5px;
            }
          }

          .video-player {
            width: 320px;
            height: 240px;
          }

          ::v-deep(.vjs-custom-skin > .video-js) {
            height: 100%;
          }
        }
      }
    }
  }

  &.z-phone {
    // padding: 0 pxtorem(25);
    margin-top: pxtorem(88) !important;
    .work-list {
      padding: pxtorem(50) pxtorem(25);
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;

      .content {
        margin-bottom: pxtorem(25);
        .video-content {
          // width: pxtorem(340);
          // height: pxtorem(245);
          .video-player {
            width: pxtorem(340);
            height: pxtorem(245);
          }

          ::v-deep(.vjs-custom-skin > .video-js) {
            height: 100%;
          }

          .collect {
            // width: pxtorem(30);
            float: right;
            img {
              width: pxtorem(30);
              height: pxtorem(30);
            }
          }
        }

        .work-content {
          img {
            width: pxtorem(340);
            height: pxtorem(245);
            object-fit: cover;
          }

          .collect {
            // width: pxtorem(30);
            float: right;
            img {
              width: pxtorem(30);
              height: pxtorem(30);
            }
          }

          // .collect {
          //   float: right;
          //   img {
          //     // width: 30px;
          //     width: 18px;
          //     height: 18px;
          //     position: relative;
          //     top: -3px;
          //     margin-right: 5px;
          //   }
          // }
        }
      }
    }
  }
}
</style>